using System.Collections.Generic;

namespace Matrix.Notification.Options
{
    /// <summary>
    /// 通知服务配置选项
    /// </summary>
    public class NotificationOptions
    {
        /// <summary>
        /// 是否启用通知服务
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 默认最大重试次数
        /// </summary>
        public int DefaultMaxRetryCount { get; set; } = 3;

        /// <summary>
        /// 默认重试间隔（毫秒）
        /// </summary>
        public int DefaultRetryIntervalMs { get; set; } = 5000;

        /// <summary>
        /// 默认超时时间（秒）
        /// </summary>
        public int DefaultTimeoutSeconds { get; set; } = 30;

        /// <summary>
        /// 批量发送默认批次大小
        /// </summary>
        public int DefaultBatchSize { get; set; } = 100;

        /// <summary>
        /// 批量发送默认间隔（毫秒）
        /// </summary>
        public int DefaultBatchIntervalMs { get; set; } = 1000;

        /// <summary>
        /// 默认并发发送数量
        /// </summary>
        public int DefaultConcurrencyCount { get; set; } = 5;

        /// <summary>
        /// 缓存过期时间（分钟）
        /// </summary>
        public int CacheExpirationMinutes { get; set; } = 5;

        /// <summary>
        /// 是否启用后台任务
        /// </summary>
        public bool EnableBackgroundJobs { get; set; } = true;

        /// <summary>
        /// 是否启用事件发布
        /// </summary>
        public bool EnableEventPublishing { get; set; } = true;

        /// <summary>
        /// 是否启用监控
        /// </summary>
        public bool EnableMonitoring { get; set; } = true;

        /// <summary>
        /// 是否启用日志记录
        /// </summary>
        public bool EnableLogging { get; set; } = true;

        /// <summary>
        /// 是否跳过重复发送
        /// </summary>
        public bool SkipDuplicateSending { get; set; } = true;

        /// <summary>
        /// 是否跳过已退订用户
        /// </summary>
        public bool SkipUnsubscribedUsers { get; set; } = true;

        /// <summary>
        /// 通知过期时间（小时）
        /// </summary>
        public int NotificationExpirationHours { get; set; } = 72;

        /// <summary>
        /// 历史记录保留天数
        /// </summary>
        public int HistoryRetentionDays { get; set; } = 30;

        /// <summary>
        /// 模板渲染配置
        /// </summary>
        public TemplateRenderingOptions TemplateRendering { get; set; } = new();

        /// <summary>
        /// 渠道配置
        /// </summary>
        public Dictionary<string, ChannelOptions> Channels { get; set; } = new();

        /// <summary>
        /// 邮件通道配置
        /// </summary>
        public Dictionary<string, object> Email { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 短信通道配置
        /// </summary>
        public Dictionary<string, object> Sms { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 推送通道配置
        /// </summary>
        public Dictionary<string, object> Push { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// Webhook通道配置
        /// </summary>
        public Dictionary<string, object> Webhook { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 自定义属性
        /// </summary>
        public Dictionary<string, object> Properties { get; set; } = new();
    }

    /// <summary>
    /// 模板渲染配置选项
    /// </summary>
    public class TemplateRenderingOptions
    {
        /// <summary>
        /// 模板引擎类型
        /// </summary>
        public string Engine { get; set; } = "Razor";

        /// <summary>
        /// 是否启用缓存
        /// </summary>
        public bool EnableCache { get; set; } = true;

        /// <summary>
        /// 缓存过期时间（分钟）
        /// </summary>
        public int CacheExpirationMinutes { get; set; } = 60;

        /// <summary>
        /// 最大模板长度
        /// </summary>
        public int MaxTemplateLength { get; set; } = 10000;

        /// <summary>
        /// 最大渲染时间（毫秒）
        /// </summary>
        public int MaxRenderTimeMs { get; set; } = 5000;

        /// <summary>
        /// 是否启用安全模式
        /// </summary>
        public bool EnableSecurityMode { get; set; } = true;

        /// <summary>
        /// 允许的函数列表
        /// </summary>
        public List<string> AllowedFunctions { get; set; } = new();

        /// <summary>
        /// 禁止的函数列表
        /// </summary>
        public List<string> ForbiddenFunctions { get; set; } = new();

        /// <summary>
        /// 默认模板数据
        /// </summary>
        public Dictionary<string, object> DefaultData { get; set; } = new();
    }

    /// <summary>
    /// 渠道配置选项
    /// </summary>
    public class ChannelOptions
    {
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 优先级
        /// </summary>
        public int Priority { get; set; } = 1;

        /// <summary>
        /// 最大发送速率（每分钟）
        /// </summary>
        public int MaxSendRatePerMinute { get; set; } = 100;

        /// <summary>
        /// 批次大小
        /// </summary>
        public int BatchSize { get; set; } = 50;

        /// <summary>
        /// 重试配置
        /// </summary>
        public RetryOptions Retry { get; set; } = new();

        /// <summary>
        /// 服务提供商配置
        /// </summary>
        public Dictionary<string, ProviderOptions> Providers { get; set; } = new();

        /// <summary>
        /// 渠道特定配置
        /// </summary>
        public Dictionary<string, object> Settings { get; set; } = new();
    }

    /// <summary>
    /// 重试配置选项
    /// </summary>
    public class RetryOptions
    {
        /// <summary>
        /// 最大重试次数
        /// </summary>
        public int MaxRetryCount { get; set; } = 3;

        /// <summary>
        /// 初始重试间隔（毫秒）
        /// </summary>
        public int InitialIntervalMs { get; set; } = 1000;

        /// <summary>
        /// 重试间隔倍数
        /// </summary>
        public double IntervalMultiplier { get; set; } = 2.0;

        /// <summary>
        /// 最大重试间隔（毫秒）
        /// </summary>
        public int MaxIntervalMs { get; set; } = 60000;

        /// <summary>
        /// 是否启用指数退避
        /// </summary>
        public bool EnableExponentialBackoff { get; set; } = true;

        /// <summary>
        /// 随机延迟范围（毫秒）
        /// </summary>
        public int RandomDelayMs { get; set; } = 1000;

        /// <summary>
        /// 需要重试的错误代码列表
        /// </summary>
        public List<string> RetryableErrorCodes { get; set; } = new();

        /// <summary>
        /// 不需要重试的错误代码列表
        /// </summary>
        public List<string> NonRetryableErrorCodes { get; set; } = new();
    }

    /// <summary>
    /// 服务提供商配置选项
    /// </summary>
    public class ProviderOptions
    {
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 提供商名称
        /// </summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 提供商类型
        /// </summary>
        public string Type { get; set; } = string.Empty;

        /// <summary>
        /// API密钥
        /// </summary>
        public string? ApiKey { get; set; }

        /// <summary>
        /// API密钥
        /// </summary>
        public string? ApiSecret { get; set; }

        /// <summary>
        /// API端点
        /// </summary>
        public string? ApiEndpoint { get; set; }

        /// <summary>
        /// 区域
        /// </summary>
        public string? Region { get; set; }

        /// <summary>
        /// 版本
        /// </summary>
        public string? Version { get; set; }

        /// <summary>
        /// 提供商特定配置
        /// </summary>
        public Dictionary<string, object> Settings { get; set; } = new();
    }
}